<?php

// 热点专题

namespace app\shop\controller;

use think\Request;
use think\Controller;
use app\shop\model\Promotion as PromotionModel;
use app\shop\model\ShopGoods as ShopGoodsModel;

class HotSpot extends Controller
{
    /**
     * 热点专题主页
     * @param Request $request
     * @param PromotionModel $promotion
     * @param ShopGoodsModel $shopGoods
     * @return mixed
     */
    public function index(Request $request, PromotionModel $promotion, ShopGoodsModel $shopGoods)
    {
        // 获取参数
        $hid = $request->param('id', '');

        // 筛选
        $condition['status'] = 1;
        if (!empty($hid)) $condition['id'] = $hid;

        // 热点专题信息
        $hotSpot = $promotion->where($condition)->order(['create_time' => 'desc'])->paginate(10, false);

        // 热点专题附属的商品
        foreach ($hotSpot as $value) {

            $value['goods'] = $shopGoods->where(['id' => ['in', $value['goods_id']]])->field('id,thumb_img')->limit(3)->select();
        }


        // // 获取商品分类信息
        // $type_arr = (new GoodsTypeModel)->where(['status' => 1])->field('id,parenTid,title')->select();
        // $menu = get_cate($type_arr);


        return $this->fetch('', [
            'mate_head' => '今日热点',
            'hot_spot'  => $hotSpot
        ]);
    }


    /**
     * 热点详情页
     * @return mixed
     */
    public function detail()
    {
        // 获取参数
        $sid = Request::instance()->param('id');

        $data = PromotionModel::get($sid);


        return $this->fetch('', [
            'mate_head' => $data['title'],
            'item'      => $data
        ]);
    }
}